package 数组;

public class 二分查找 {
    public static void main(String[] args) {
        int [] arr = new int[]{-33, -26, -22, -4, 12, 34, 77, 99};
        int head = 0, end = arr.length - 1, mid;
        int a = 99;
        boolean flag = true;
        while(head <= end){
            mid = (head + end) / 2;
            if(a == arr[mid]){
                flag = false;
                System.out.println("查找成功！所在位置：" + mid);
                break;
            }
            else if(a < arr[mid])
                end = mid - 1;
            else
                head = mid + 1;
        }
        if(flag)
            System.out.println("很遗憾，该数组不存在你要查找的值！");
    }
}
